package com.tubruk.trackme;

import java.util.ArrayList;

import com.tubruk.adapter.OptionAdapter;
import com.tubruk.database.OptionDB;
import com.tubruk.object.IOption;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;

public class Options extends Activity {

	@Override
	  public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.options);

	    ArrayList<IOption> items = OptionDB.getAllOptions();

	    if (items != null){
		    OptionAdapter adapter = new OptionAdapter(this, R.id.optionList, items);
			//adapter.setActivity(this);
			
			//bind list
		    ListView list = (ListView) this.findViewById(R.id.optionList);
			list.setAdapter(adapter);
	    }
	    
	    ImageButton locate = (ImageButton) findViewById(R.id.locate);
		locate.setOnClickListener(new ActionClickListener(Options.this, TrackMapActivity.class));
		
		ImageButton search = (ImageButton) findViewById(R.id.search);
		search.setOnClickListener(new ActionClickListener(Options.this, History.class));
	}
	
	private class ActionClickListener implements OnClickListener {
		private Class target;
		private Context source;
		
		public ActionClickListener(Context source, Class target){
			this.source = source;
			this.target = target;
		}
		
		public void onClick(View v) {
			finish();
			Intent i = new Intent(source, target);
			startActivity(i);
		}
		
	} 
}
